<%@ page import="java.util.List" %>
<%@ page import="com.nus.beans.Leave" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%--
  Created by IntelliJ IDEA.
  User: dell
  Date: 9/23/12
  Time: 12:26 PM
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<script type="text/javascript">
function submitForm(action) {
    form = document.getElementById('leavesForm');

    form.action = action;
    form.submit();
}
</script>
    <%
          String errorMessage = (String) request.getAttribute("ERROR_MESSAGE");


    %>
<title>Pending Leave Requests</title></head>
<body>
<table>
    <tr>
        <td></td>
        <td>Leave Date</td>
        <td>Applied Date</td>
        <td>Applied By</td>
        <td>Leave Status</td>
    </tr>

        <form method="post" id="leavesForm">

    <%  List<Leave> leaves = (List<Leave>) request.getAttribute("leavesList");
        Leave leave;
         SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        for (int i = 0; i < leaves.size(); i++){
            leave = leaves.get(i);
            %>
    <tr>

        <td><input type="checkbox" name="<%= leave.getDate().getTime()%>_<%=leave.getAppliedBy()%>" value="<%=leave.getAppliedBy()%>"></td>
        <td><%= formatter.format(leave.getDate()) %></td>
        <td><%= formatter.format(leave.getAppliedDate()) %></td>
        <td><%= leave.getAppliedByName() %></td>
        <td><%= leave.getStatus().toString() %></td>


    </tr>
                    <% } %>

            <tr><td colspan="8">
                <% if(errorMessage != null){%>
                    <%=errorMessage%>
                <% } %>
            </td></tr>

    <tr>
        <td colspan="2"><input type="button" value="Verify" onclick="submitForm('verifyLeaves.do')"/> </td>
        <td colspan="2"> <input type="button" value="Reject" onclick="submitForm('rejectLeaves.do')"/> </td>
        <td colspan="4"> <a href="viewHome.do">Home</a></td>
    </tr>
       </form>
</table>


</body>
</html>